class Solution(object):
    def flipgame(self, fronts, backs):
        """
        :type fronts: List[int]
        :type backs: List[int]
        :rtype: int
        """
        no_set = set()
        n = len(fronts)
        min_val = 0
        for i in range(n):
            if fronts[i] == backs[i]:
                no_set.add(fronts[i])
        for i in range(n):
            if fronts[i] not in no_set:
                if min_val == 0:
                    min_val = fronts[i]
                else:
                    min_val = min(fronts[i], min_val)
            if backs[i] not in no_set:
                if min_val == 0:
                    min_val = backs[i]
                else:
                    min_val = min(backs[i], min_val)
        return min_val




data = Solution()
fronts = [1, 2, 4, 4, 7]
backs = [1, 3, 4, 1, 3]
print(data.flipgame(fronts, backs))
